﻿using System.Collections.Generic;
using System.Diagnostics.Contracts;

namespace OpenLS.Spreadsheet
{
    abstract class MultiDimensionRegion<T>: CellRegion where T: Dimension
    {
        protected readonly T _dim1;
        protected readonly T _dim2;

        protected MultiDimensionRegion(T dim1, T dim2)
        {
            Contract.Requires(dim1 != null);
            Contract.Requires(dim2 != null);
            _dim1 = dim1;
            _dim2 = dim2;            
        }

        protected override sealed IEnumerable<Cell> GetAllCells()
        {
            return Enumerable.SelectMany(GetDimensions(), r => r.GetNonEmptyCells());
        }

        protected abstract IEnumerable<T> GetDimensions();
    }
}